import java.io.*;
import myutil.MyInput;

class Node {
    int data;
    Node next;
    public Node(int data, Node ref) {
	this.data = data;
	this.next = ref;
    }
}

public class Queue
{
    Node NodeHead;
    Node NodeEnd;
    int length;
    
    public Queue() {
	NodeHead = null;
	NodeEnd = null;
	length = 0;	
    }
    
    public void  push(int data) {
	Node new_node = new Node(data,null);
	if (NodeHead == null) {
	     NodeHead = new_node;
	}
	else {
	    NodeEnd.next = new_node;
	}
	NodeEnd = new_node ;
	length++;
    }
    
    public int pop () {
        if(NodeHead == null) {
            return 0;
        }
        int data = NodeHead.data;
        NodeHead = NodeHead.next;
        return data;
        
    }
    
    public void display() {
	Node TempNodeHead = this.NodeHead;
	while (TempNodeHead != null)
	{
	    System.out.println(TempNodeHead.data);
	    TempNodeHead = TempNodeHead.next;
	}
    }

    /**
     * @param args
     */
    public static void main(String[] args)
    {
	Queue  q = new Queue();
	q.push(1);
	q.push(2);
	q.push(3);
	q.push(4);
	q.pop();
	q.push(5);
	q.display();
	q.push(6);
	//q.display();

	// TODO Auto-generated method stub

    }

}
